<?php
namespace app\modules\system\actions;

use app\lib\ActionBase;
use app\service\data as data;
use app\lib\Code;



class Image extends ActionBase {
    
    private $_image_data;
    
    //图片id
    public $image_id;
    
    
    public function __construct() {
        $this->_image_data= new data\Image();
    }
    
    public function rules() {
        return [
            //图片识别列表
            ['image_id','required','on'=>'recognitionlist', 'message'=>'图片id不能为空'],
            
            //图片识别列表
            ['image_id','required','on'=>'downloadimage', 'message'=>'图片id不能为空'],
        ];
    }
    
    
    //用户-图片列表
    public function ImageList($arrInput) {
        $arrInput['page'] = $arrInput['page'] ?? 1;
        $arrInput['page_size'] = $arrInput['page_size'] ?? 10;
        return $this->_image_data->ImageList($arrInput);
    }
    
    //图片识别列表
    public function RecognitionList($arrInput) {
        $this->setScenario("recognitionlist");
        $this->load($arrInput,'');
        if (!$this->validate()) {
            formatJson(Code::PARAM, $this->parseErrors2str($this->firstErrors));
        }
        $arrInput['page'] = $arrInput['page'] ?? 1;
        $arrInput['page_size'] = $arrInput['page_size'] ?? 10;
        return $this->_image_data->RecognitionList($arrInput);
    }
    
    public function DownloadImage($arrInput) {
        $this->setScenario("downloadimage");
        $this->load($arrInput,'');
        if (!$this->validate()) {
            formatJson(Code::PARAM, $this->parseErrors2str($this->firstErrors));
        }
        
        return $this->_image_data->DownloadImage($arrInput['image_id']);
    }
}